<template xmlns="http://www.w3.org/1999/html">
  <a-modal
    :title="title"
    :visible="visible"
    @cancel="handleCancel"
    :maskClosable="false"
    width="75%"
  >
    <template slot="footer">
      <a-button @click="handleCancel">取消</a-button>
      <a-button @click="handleOk" type="primary" v-if="!detailDis">提交</a-button>
      <a-button @click="handleCheck('2')" type="primary" v-if="checkDis">驳回</a-button>
      <a-button type="primary" @click="handleCheck('5')" v-if="checkDis">通过</a-button>

    </template>
    <!--    ('订单收款')-->
    <div class="firstLine">
      <a-form :form="form">
        <!--      基本信息-->
        <a-card style="margin-bottom: 10px">
          <div class="essential" style="border-bottom: 1px dashed #eae2e2;">
            <div class="essential_text">基本信息</div>

            <a-row :gutter="24">
              <a-col :md="8" :sm="24">
                <a-form-item
                  :labelCol="labelCol"
                  :wrapperCol="wrapperCol"
                  label="经销商名称">
                  <a-input-search v-decorator="['custName',validatorRules.custName]" placeholder="请选择经销商信息"
                                  :disabled="detailDis" readOnly enter-button @search="custSearch" />
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item
                  :labelCol="labelCol"
                  :wrapperCol="wrapperCol"
                  label="经销商编号"
                  >
                  <a-input v-decorator="['custCode',validatorRules.custCode]" placeholder="请选择经销商信息" readOnly />
                </a-form-item>
              </a-col>

              <a-col :md="8" :sm="24">
                <a-form-item
                  :labelCol="labelCol"
                  :wrapperCol="wrapperCol"
                  label="收货地址"
                  >
                  <!--                  @change="handleChange"-->
                  <a-select
                    v-decorator="['address',validatorRules.custCode]"
                    placeholder="请选择收货地址"
                    @change="e =>{AdressChange(e)}"
                  >
                    <a-select-option v-for="(item,index) in userInfo" :key="index" :value="item.address">
                      {{ item.address }}
                    </a-select-option>
                  </a-select>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">

                <a-form-item
                  :labelCol="labelCol"
                  :wrapperCol="wrapperCol"
                  label="送达方"
                  >
                  <!--                  @change="handleChange"-->
                  <a-input placeholder="请选择收货地址" v-decorator="['kunweName',validatorRules.kunweName]" readOnly />
                </a-form-item>
              </a-col>

              <!--              <a-col :md="8" :sm="24">-->
              <!--                <a-form-item-->
              <!--                  :labelCol="labelCol"-->
              <!--                  :wrapperCol="wrapperCol"-->
              <!--                  label="送达地点"-->
              <!--                  >-->
              <!--                  <a-input placeholder="请输入送达方名称" v-decorator="['kunweName',validatorRules.kunweName]" />-->
              <!--                </a-form-item>-->
              <!--              </a-col>-->
              <a-col :md="8" :sm="24">
                <a-form-item
                  :labelCol="labelCol"
                  :wrapperCol="wrapperCol"
                  label="收货人"
                  >
                  <a-input placeholder="请选择收货地址" v-decorator="['consignee',validatorRules.consignee]" readOnly />
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item
                  :labelCol="labelCol"
                  :wrapperCol="wrapperCol"
                  label="收货人电话"
                  >
                  <a-input placeholder="请选择收货地址" v-decorator="['consigneePhone',validatorRules.consigneePhone]"
                           readOnly />
                </a-form-item>
              </a-col>
            </a-row>

          </div>
        </a-card>
        <!--      订货信息-->
        <a-card style="margin-bottom: 10px">
          <div class="essential">
            <div class="essential_text">订货信息</div>
            <a-table :scroll="{ x:1900,y:600 }" :columns="columns" :data-source="dataSource" bordered
                     :pagination="false">
              <template slot="promotionPolicy" slot-scope="text, record">
                <a-tag color="#3498db" style="padding: 1px" @click="record.productType == 0 ? policyTag(record):'' ">
                  {{ record.productType == 0 ? record.promotionName || '请选择政策' : record.productType == 1 ? '赠品' : record.productType == 2 ? '货补商品' : ''
                  }}
                </a-tag>
              </template>
              <!--          单位-->
              <template slot="saleUnit" slot-scope="text, record">
                <span>{{ text }}</span>
              </template>
              <!--          订单数量-->
              <template slot="num" slot-scope="text,record">
                <a-input type="number" style="width: 80px" v-model="text" :min="0" :disabled="record.productType == 1"
                          @change="onCellChangeCode(record, 'num', text)" />
              </template>
              <!--          折扣价-->
              <!--              <template slot="disPrice" slot-scope="text,record">-->
              <!--                <a-input type="number" style="width: 80px" v-model="text" :min="0" :disabled="record.proDcutType"-->
              <!--                         @change="onCellChangeCode(record, 'disPrice', text)" />-->
              <!--              </template>-->
              <!--              &lt;!&ndash;          折扣率&ndash;&gt;-->
              <!--              <template slot="discountRate" slot-scope="text,record">-->
              <!--                <a-input type="number" style="width: 80px" v-model="text" :min="0" :disabled="record.proDcutType"-->
              <!--                         @change="onCellChangeCode(record, 'discountRate', text)" />-->
              <!--              </template>-->
              <!--              &lt;!&ndash;          折扣金额&ndash;&gt;-->
              <!--              <template slot="favourableAmount" slot-scope="text,record">-->
              <!--                <span>{{ text | moneyTwoPoint }}</span>-->
              <!--              </template>-->
              <!--              &lt;!&ndash;              小计金额&ndash;&gt;-->
              <!--              <template slot="itemAmount" slot-scope="text,record">-->
              <!--                <span>{{ text | moneyTwoPoint }}</span>-->
              <!--              </template>-->
              <!--          备注-->
              <template slot="remarks" slot-scope="text,record">
                <a-input type="text" style="width: 80px" v-model="text" placeholder="请输入"
                         @change="onCellText(record, 'remarks', text)" />
              </template>
              <!--          删除按钮-->
              <template slot="action" slot-scope="text, record,index">
                <a :disabled="detailDis" @click="handleDeleteSelected(record,index)">删除</a>
              </template>
            </a-table>
            <div style="margin: 8px 2px;color: #2276d2;border-bottom: 1px dashed #e8e8e8;padding-bottom: 8px">
              <a :disabled="detailDis" @click="handleAddgoods(0)" style="margin-right: 8px">+ 添加商品</a>
              <a :disabled="detailDis" @click="AddgoodMore(2)">+ 添加货补</a>
            </div>
          </div>

          <div class="Poolbalance">
            <div class="remain">
              <span class="remainF">资金余额:<span style="margin: 0 4px"> {{ alwaysMoney.capitalBalance || 0
                }}</span></span>
              <span class="remainF">货补余额:<span style="margin: 0 4px">{{ alwaysMoney.hbBalance || 0 }}</span></span>
              <span class="remainF">折扣余额:<span style="margin: 0 4px">{{ alwaysMoney.discountBalance || 0
                }}</span></span>
              <span class="remainF">使用折扣:<span style="margin: 0 4px">
                <a-input type="number" @change="numberChange"
                         :disabled="detailDis"
                         style="display: inline-block;width: 120px;border: none;border-bottom: 1px solid black;border-radius: unset"
                         :min="0"
                         v-model="alwaysMoney.discountAmount" /></span></span>
            </div>
            <div class="remain">
              <span class="remainF">使用货补:<span style="margin: 0 4px">{{ MoneyParams.hbFee || 0 }}</span></span>
              <span class="remainF">订单总额:<span style="margin: 0 4px">{{ MoneyParams.totalAmount || 0 }}</span></span>
              <span class="remainF">实际金额:<span style="margin: 0 4px">{{ MoneyParams.realAmount || 0 }}</span></span>
              <span class="remainF">优惠金额:<span style="margin: 0 4px">{{ MoneyParams.disAmount || 0 }}</span></span>
            </div>
          </div>
        </a-card>

        <!--其他信息区域-->
        <a-card>
          <div class="essential">
            <div class="essential_text">其他信息</div>
          </div>
          <a-form-item label="" :labelCol="{
                     xs: { span: 24 },
                     sm: { span: 0 }
                     }"
                       :wrapperCol="{
                     xs: { span: 24 },
                     sm: { span: 20 }
                     }">
            <upload-image
              class="avatar-uploader"
              text="添加图片"
              v-decorator="['imgs', {}]"
              :limit="5"
            />
            <!--        v-decorator="[ 'actFileUrl', validatorRules.actFileUrl]"-->
          </a-form-item>
        </a-card>
      </a-form>
    </div>
    <proChose ref="prochoose" @okbro="okbropro"></proChose>
    <policys ref="policysModal" v-bind="policysData" @polocyOk="polocyOk"></policys>
    <!--    添加商品-->
    <productcontact ref="productModal" @productcontact="productcontacts" v-bind="productConfig"></productcontact>
    <!--订单支付-->
    <!--    <payOrders ref="IsPayOrders"></payOrders>-->
    <template>
      <a-modal v-model="payShow" title="提示" @cancel="handleToCancel1" @ok="handleToCancel1" style="z-index:999;">
        <template slot="footer">
          <a-button @click="handleToCancel1" type="primary">完成</a-button>
        </template>
        <div class="orderPay">
          <!--      <div class="payItems">剩余时间：<span class="payText">00:00:00</span></div>-->
          <div class="payItems">支付前信用余额：<span class="payText">{{ payList.old }}</span></div>
          <div class="payItems">需扣减：<span class="payText">{{ payList.used }}</span></div>
          <div class="payItems">支付后信用余额：<span class="payText">{{ payList.new }}</span></div>
        </div>
      </a-modal>
    </template>

  </a-modal>
</template>

<script>
import { pick } from 'lodash'
// import payOrders from './payOrders'
import productcontact from '@/components/cn-components/ProductContact'
// import TerminalChose from '@/components/cn-components/TerminalChose'
import JInput from '@/components/cn-form/JInput.vue'
// import appStores from '@/views/mdm/couponStore/modules/appStores'
import { getAction, postAction } from '@/api/manage'
import UploadImage from '@/components/upload-image/UploadImage'
import proChose from '@comp/cn-components/ProChose'
import policys from '@comp/cn-components/Policys'

import { login } from '../../../../api/login'

export default {
  name: 'OrderBehalf',
  components: { UploadImage, productcontact, proChose, policys },
  data() {
    return {
      userInfo: [],
      detailDis: false,
      checkDis: false,
      title: '客服订单',
      payShow: false,
      terminalNames: '',
      linkman: '',
      phone: '',
      alwaysMoney: {},
      MoneyParams: {},
      // unicodess: [],
      // 处理订货信息表格
      inputsValue: [],
      settings: {
        name: '门店',
        displayKey: 'terminalName',
        returnKeys: ['id', 'terminalCode'],
        listUrl: '/cnTerminalController/custFindTerminalList',
        queryParamCode: 'terminalName',
        queryParamText: '门店名称',
        columns: [
          { title: '门店编号', dataIndex: 'terminalCode', align: 'center', width: '50%', widthRight: '70%' },
          { title: '门店名称', dataIndex: 'terminalName', align: 'center', width: '50%', widthRight: '70%' }
        ]
      },
      // appStores初始化
      selectOption: {},
      selectValue: {},
      usemoney: 0,
      // 收货地址列表
      visible: false,
      dataSource: [],
      form: this.$form.createForm(this),
      labelCol: {
        xs: { span: 24 },
        sm: { span: 6 }
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 18 }
      },
      labelCol1: {
        xs: { span: 24 },
        sm: { span: 0 }
      },
      wrapperCol1: {
        xs: { span: 24 },
        sm: { span: 24 }
      },
      modal: {},
      selectedRowKey: [],
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 50,
          align: 'center',
          customRender: function(t, r, index) {
            return parseInt(index) + 1
          }
        },
        {
          title: '商品编号',
          align: 'center',
          dataIndex: 'productCode'
        },
        {
          title: '商品名称',
          align: 'center',
          width: 300,
          dataIndex: 'productName'
        },
        {
          title: '商品类型',
          align: 'center',
          dataIndex: 'productType',
          customRender: (r, t, index) => {
            if (r == 0) {
              return '本品'
            } else if (r == 2) {
              return '货补'
            } else if (r == 1) {
              return '赠品'
            }
          }
        },
        {
          title: '促销政策',
          align: 'center',
          dataIndex: 'promotionPolicy',
          width: 150,
          scopedSlots: { customRender: 'promotionPolicy' }
        },
        {
          title: '促销名称',
          align: 'center',
          dataIndex: 'promotionName',
          width: 150,
          scopedSlots: { customRender: 'promotionName' }
        },
        {
          title: '单位',
          align: 'center',
          dataIndex: 'vrkmet',
          scopedSlots: { customRender: 'vrkmet' }
        },
        {
          title: '订货数量',
          align: 'center',
          dataIndex: 'num',
          scopedSlots: { customRender: 'num' }
        },
        {
          title: '订货价/元',
          align: 'center',
          dataIndex: 'price'
        },
        // {
        //   title: '小计/元',
        //   align: 'center',
        //   dataIndex: 'itemAmount',
        //   scopedSlots: { customRender: 'itemAmount' }
        // },
        {
          title: '备注',
          align: 'center',
          dataIndex: 'remarks',
          scopedSlots: { customRender: 'remarks' }
        },
        {
          title: '操作',
          align: 'center',
          dataIndex: 'action',
          fixed: 'right',
          width: 120,
          scopedSlots: { customRender: 'action' }
        }
      ],
      validatorRules: {
        custCode: { rules: [{ required: true, message: '' }] },
        consignee: { rules: [{ required: true, message: '' }] }
      },
      payList: {
        old: 0,
        used: 0,
        new: 0
      },
      url: {
        givMoneyUrl: window._CONFIG['domianDmsURL'] + '/order/orderSettle',
        terminalAdress: window._CONFIG['domianURL'] + '/cnShippingAddressController/getAddressByCode',
        remainMoney: window._CONFIG['domianURL'] + '/cart/DmsFictitiousCart/getPoolAndCredit',
        saveOrder: window._CONFIG['domianDmsURL'] + '/order/saveOrUpdateEntity',
        getQrcode: window._CONFIG['domianURL'] + '/cnOrderController/getPayQrCode',
        checkOrder: window._CONFIG['domianDmsURL'] + '/order/orderCheck'
      },
      prosource1: [],
      prosource2: [],

      timer: null,
      addressCord: {}
    }
  },
  // computed: {
  //   configs() {
  //     return Object.assign({ value: this.value }, this.settings, this.$attrs)
  //   }
  // },
  created() {
    // this.Dictionary()
  },
  watch: {},
  methods: {
    kunweChange(e) {
      console.log(e)
    },
    numberChange(e) {
      let vm = this
      clearTimeout(this.timer)
      return function() {
        vm.timer = setTimeout(() => {
          vm.alwaysMoney.discountAmount = e.target.value
          if (vm.alwaysMoney.discountAmount > vm.alwaysMoney.discountBalance) {
            vm.$message.info('折扣金额不能大于折扣余额，请重新输入')
            vm.$set(vm.alwaysMoney, 'discountAmount', 0)
            console.log(vm.MoneyParams)
            return
          }
          vm.MoneyParams.realAmount = vm.MoneyParams.totalAmount - vm.MoneyParams.disAmount - e.target.value

        }, 2000)
      }()
    },
    handlers(val, layOut) {
      let _this = this
      clearTimeout(this.timeout)
      this.timeout = setTimeout(() => {
        _this.handlerData(val)
      }, layOut)
    },
    settleMent() {
      let params = {
        reqVos: this.dataSource,
        custCode: this.form.getFieldValue('custCode')
      }
      postAction(this.url.givMoneyUrl, { ...params }).then(res => {
        if (!res.success) {
          this.$message.error(res.message)
          return
        }
        let array1 = []
        let array2 = []
        res.result.productItem.forEach(item =>{
          if(item.productType == 0 ){
            this.MoneyParams = Object.assign(pick(res.result, 'realAmount', 'totalAmount', 'disAmount','hbFee'))
            array1.push(item)
            array1.forEach(item => {
              item.children = item.gift
            })
          }else if(item.productType == 2){
            this.MoneyParams = Object.assign(pick(res.result, 'realAmount', 'totalAmount', 'disAmount','hbFee'))
            array2.push(item)
          }
        })
        this.prosource2 =JSON.parse(JSON.stringify(array2))
        this.prosource1 = JSON.parse(JSON.stringify(array1))
        this.dataSource = [...this.prosource1, ...this.prosource2]
        console.log(this.prosource2)
        console.log('556')
        console.log(this.prosource1)
      })
    },
    polocyOk(value, value2) {
// TODO value政策数据，value2辨别数据
      let code = value2.productCode
      let count = null
      this.dataSource.forEach((item, index) => {
        if (!item.detailDis && item.productCode == code) {
          item.promotionPolicy = value[0].promotionCode
          item.promotionName = value[0].promotionName
          count = index
        }
      })
      if (count !== null) {
        let target = this.dataSource[count]
        this.$set(this.dataSource, count, target)
      }
      this.$nextTick(() => {
        this.settleMent()
      })
    },
    AdressChange(e) {
      const target = this.userInfo.find(item => item.id = e)
      console.log(target)
      this.addressCord = target
      if (target) {
        this.form.setFieldsValue({
          kunweName: target.kunweName,
          consignee: target.linkman,
          consigneePhone: target.telephone
        })
      }
    },
    policyTag(cord) {
      if(this.detailDis){
        return
      }
      let params = {
        productCode: cord.productCode,
        custCode: this.form.getFieldValue('custCode'),
        num: cord.num,
        detailDis: cord.detailDis
      }
      this.$refs.policysModal.edit(params)

    },

    // 选择经销商后的选择
    okbropro(record) {
      let codes = record[0].custCode
      if (record) {
        this.dataSource = []
        this.prosource1 = []
        this.prosource2 = []
        this.addressCord = {}
        this.form.resetFields()
        let obj = Object.assign({}, record[0])
        this.form.setFieldsValue(pick(obj, 'custName', 'custCode'))
      }
      // 收货地址
      const custUrl = '/customerController/findAddress'
      // 资金列表
      const moneyUrl =  window._CONFIG['domianDmsURL'] + '/order/custBalance'
      // 送达方
      // const enterUrl = '/cnShippingKunwe/getByCustCode'
      if (record.length !== 0) {
        return Promise.all([
          getAction(custUrl, { custCode: codes }),
          getAction(moneyUrl, { custCode: codes })
        ]).then(([Address, Balance]) => {
          if (Address.result && Address.result.length) {
            this.userInfo = Address.result
          }
          if (Balance.result) {
            this.alwaysMoney = Object.assign(pick(Balance.result, 'capitalBalance', 'hbBalance', 'discountBalance', 'discountAmount'))
          }
        }).catch(res => {

        })
      }
    },
    custSearch() {
      this.$refs.prochoose.rowKey = 'custCode'
      let formconfig = [
        {
          key: 'custCode',
          label: '经销商编号'
        },
        {
          key: 'custName',
          label: '经销商名称'
        }
      ]
      let tableconfig = {
        columns: [
          {
            title: '经销商编号',
            align: 'center',
            dataIndex: 'custCode',
            width: 120,
            ellipsis: true
          },
          {
            title: '经销商名称',
            align: 'center',
            dataIndex: 'custName',
            width: 120,
            ellipsis: true
          }
        ],
        list: window._CONFIG['domianURL'] + '/customerController/getPageList',
        multiple: false,
        columW: 15
      }
      this.name = '经销商'
      let dataSource = []
      if (this.form.getFieldValue('custName')) {
        dataSource = [{
          custName: this.form.getFieldValue('custName'),
          custCode: this.form.getFieldValue('custCode')
        }]
      }
      this.$refs.prochoose.edit(formconfig, tableconfig, 'custName', 'custCode', dataSource)
    }
    ,
    // Dictionary() {
    //   let that = this
    //   getAction(window._CONFIG['domianURL'] + `/cnDictionaryController/getDictByCode`, { dictCode: 'product_saleUnit' }).then(res => {
    //     console.log(res)
    //     that.unicodess = res.result
    //     console.log(that.unicodess)
    //   })
    // },
    // getinputsvalue(value) {
    //   if (value.length == 0) {
    //     this.$message.info('请选择门店')
    //     return
    //   }
    //   let terminalArray = Object.assign({}, value[0])
    //   if (value) {
    //     this.linkman = terminalArray.linkman,
    //       this.phone = terminalArray.telephone
    //     this.$nextTick(() => {
    //       this.form.setFieldsValue({
    //         address: terminalArray.province + '-' + terminalArray.city + '-' + terminalArray.area + '-' + terminalArray.address,
    //         telephone: terminalArray.linkman + '-' + terminalArray.telephone
    //       })
    //     })
    //   }

    edit(record, status) {
      this.visible = true
      this.detailDis = false
      this.checkDis = false
      if (status == 'forOrderDetail' || status == 'check') {
        this.detailDis = true
        this.$nextTick(() => {
          this.modal = record
          this.form.setFieldsValue(pick(this.modal, Object.keys(this.modal)))
          this.dataSource = this.modal.items
          this.MoneyParams = pick(this.modal, 'totalAmount', 'realAmount', 'disAmount','hbFee')
          this.alwaysMoney = pick(this.modal, 'capitalBalance', 'hbBalance', 'discountBalance', 'discountAmount')
        })
        console.log(status)
        if (status == 'check') {
          this.checkDis = true
        }
        return
      }
      this.form.resetFields()
      this.terminalNames = ''
      this.dataSource = []
      this.MoneyParams = {}
      this.alwaysMoney = {}
    }
    ,
    // 选择支付方式
    // handleChangePay(value) {
    //   // this.$set(this.queryParam, 'payment', value)
    //   this.form.setFieldsValue({
    //     payment: value
    //   })
    // },
    // 选择收货地址
    // inputsome(value) {
    //   if (value == '' || value == undefined) {
    //     this.$message.error('门店已置空')
    //     return
    //   }
    // },
    // 添加商品点击事件
    handleAddgoods(value) {

      let CODE = this.form.getFieldValue('custCode')
      if (!CODE) {
        this.$message.info('请先选择经销商')
        return
      }

      let url =  window._CONFIG['domianDmsURL'] + '/product-center/findPageListByCust'
      let load = {
        way: 'post',
        params: {
          custCode: CODE
        }
      }
      // TODO value:关键字 url列表数据 load请求数据
      this.$refs.productModal.visitproducts(value, url, this.prosource1, load)
    },
    // 添加货补
    AddgoodMore(value) {
      console.log(this.prosource2)
      let CODE = this.form.getFieldValue('custCode')
      if (!CODE) {
        this.$message.info('请先选择经销商')
        return
      }
      let url = window._CONFIG['domianDmsURL'] + '/dmsFeePoolController/findPageListProductCode'
      let load = {
        way: 'post',
        params: {
          custCode: CODE
        }
      }
      postAction(url, { ...load.params }).then(res => {
        let that = this
        if (!res.success || res.result.length == 0) {
          that.$message.info('该用户暂无货补商品')

        } else {
          // TODO value:关键字 url列表数据 load请求数据
          that.$refs.productModal.visitproducts(value, url, that.prosource2, load)
        }
      })
    },
    productcontacts(value, type) {
      if (type == 0) {
        value.forEach(item => {
          item.num = 1
          item.productType = type
          item.detailDis = false
        })
        this.prosource1 = value
        this.$nextTick(() => {
          this.settleMent()
        })
      } else if (type == 2) {
        value.forEach(item => {
          item.num = 1
          item.productType = type
          item.detailDis = true
        })
        this.prosource2 = value
      }
      this.dataSource = [...this.prosource1, ...this.prosource2]
      this.$nextTick(() => {
        this.settleMent()
      })
    },
    onCellChangeCode(key, dataIndex, value) {
      const dataSource = [...this.dataSource]
      const target = dataSource.find(item => item == key)
      value ? value == 0 : value = value
      if (target) {
        target[dataIndex] = value
        target.itemAmount = (target.num - 0) * (target.price - 0)
        this.dataSource = dataSource
      }
      this.$nextTick(() => {
        this.settleMent()
      })
    },
    onCellText(cord, dataIndex, value) {
      const dataSource = [...this.dataSource]
      const target = dataSource.find(item => item == cord)
      if (target) {
        target[dataIndex] = value
        this.dataSource = dataSource
      }
    },
    // 本品/赠品选择
    // onCellChangeCode(key, dataIndex, value) {
    //   const dataSource = [...this.dataSource]
    //   const target = dataSource.find(item => item === key)
    //   target.minDisPrice == null ? target.minDisPrice = 0 : target.minDisPrice = target.minDisPrice
    //   let a = parseInt(value)
    //   if (dataIndex == 'disPrice' && a < target.minDisPrice) {
    //     this.$message.info('折扣价不得低于商品最低价，请确认价格')
    //     target[dataIndex] = target.minDisPrice
    //     this.dataSource = dataSource
    //     return
    //   }
    //   if (target) {
    //     value = value.replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3')
    //     target[dataIndex] = value
    //     this.dataSource = dataSource
    //   }
    //   if (dataIndex == 'disPrice' || dataIndex == 'num') {
    //     if (target.custPrice == 0) {
    //       console.log('原价为0,不计算')
    //     } else {
    //       if (target.disPrice > target.custPrice) {
    //         this.$message.info('商品折扣价不能大于原价,请重新输入')
    //         target.disPrice = target.custPrice
    //         return
    //       } else {
    //         if (target.disPrice == 0) {
    //           target.itemAmount = target.custPrice * target.num
    //         } else {
    //           target.itemAmount = target.disPrice * target.num
    //         }
    //         target.favourableAmount = target.custPrice - 0 - target.disPrice - 0
    //         target.discountRate = parseInt((target.favourableAmount / target.custPrice) * 100)
    //         target[dataIndex] = value
    //         this.dataSource = dataSource
    //       }
    //     }
    //   }
    //   if (dataIndex == 'discountRate') {
    //     if (target.discountRate > 100 || target.discountRate < 0) {
    //       this.$message.info('商品折扣率取值错误,请重新输入')
    //       target.discountRate = 0
    //       target.disPrice = target.custPrice
    //       target.favourableAmount = 0
    //       return
    //     } else {
    //       target.disPrice = target.custPrice * (1 - target.discountRate / 100)
    //       target.disPrice = Math.round(target.disPrice * 100) / 100
    //       if (target.disPrice < target.minDisPrice && target.disPrice > 0) {
    //         target.disPrice = target.minDisPrice
    //         target.discountRate = 0
    //         this.$message.info('商品折扣后的价格不应低于最低折扣价，请重新输入')
    //         return
    //       }
    //       target.favourableAmount = Math.round((target.custPrice - 0 - target.disPrice - 0) * 100) / 100
    //       target.itemAmount = target.disPrice * target.num
    //     }
    //   }
    //   this.totalPrice(this.dataSource)
    // },
    handleToCancel1() {
      this.payShow = false
      this.payList = {
        old: 0,
        used: 0,
        new: 0
      },
        this.$emit('ok')
      this.handleCancel()
    }
    ,

    // 表格行内订单数量
    // 点击删除事件
    handleDeleteSelected(cord, index) {
      if (cord.detailDis) {
        let dataSou = this.prosource2
        this.prosource2 = dataSou.filter(item => item !== cord)
      } else {
        let dataSou2 = this.prosource1
        this.prosource1 = dataSou2.filter(item => item !== cord)
      }
      this.dataSource = [...this.prosource2, ...this.prosource1]
      this.$nextTick(() => {
        this.settleMent()
      })
    },
    // 计算总价
    // totalPrice(Array) {
    //   this.params.oldTotalAmount = 0
    //   this.params.disAmount = 0
    //   Array.forEach(item => {
    //     this.params.oldTotalAmount += (item.custPrice * item.num)
    //     this.params.disAmount += (item.favourableAmount * item.num)
    //   })
    //   this.params.realPayAmount = this.params.oldTotalAmount - this.params.usedAmount - this.params.disAmount
    //   if (this.params.realPayAmount < 0) {
    //     this.params.realPayAmount = 0
    //   }
    // }
    // ,

    // 设置行属性
    onClickRow(record) {
      return {
        on: {
          click: () => {
            console.log(record)
            let key = record.details
            if (this.selectedRowKey.indexOf(key) == -1) {
              this.selectedRowKey = [key]
            } else {
              this.selectedRowKey.remove(key)
            }
          }
        }
      }
    },
// 确认提交事件
    handleOk(title) {
      const that = this
      let goon = ''
      if (that.dataSource.length == 0) {
        this.$message.error('商品列表不能为空')
        return
      }
      this.form.validateFields((err, values) => {
        if (!err) {
          let formDate = Object.assign({}, values, { ...this.MoneyParams },{...this.alwaysMoney})
          const extendVos = []
          if (values.imgs && values.imgs.length) {
            values.imgs.slice(0).map((url, index) => {
              extendVos.push({
                dataType: 1,
                code: url,
                orderNum: index
              })
            })
          }
          formDate.items = this.dataSource
          formDate.telphone = this.phone
          formDate.receiver = this.linkman
          formDate.address = this.addressCord.address
          formDate.kunwe = this.addressCord.kunwe
          formDate = { ...formDate, ...this.params }
          postAction(this.url.saveOrder, formDate).then(res => {
            // 储存数据成功
            if (res.success) {
              that.$message.success(res.message)
              // 这里放二维码获取  客服订单获取二维码环节
              // let paypage = this.getQrcode(res.result.orderCode)
              // this.$refs.IsPayOrders.edit(paypage, title)
              if (res.result.payment == '20') {
                this.payList = {
                  old: res.result.usableQuota,
                  new: res.result.surplusUsableQuota,
                  used: res.result.realPayAmount
                }
                this.payShow = true
              } else {
                this.handleToCancel1()
              }
            } else {
              that.$message.warning(res.message)
            }
          })
        } else {
          this.$message.info('请检查表格必填项')
        }
      })
    },
    // 审核通过事件
    handleCheck(status) {
      let param = {...this.modal,orderStatus:status}
      postAction(this.url.checkOrder, param).then(res => {
       if(!res.success){
         this.$message.error(res.message)
         return
       }
        this.handleToCancel1()
      })

    },
    // 获取二维码
    getQrcode(code) {
      getAction(this.url.getQrcode, { orderCode: code }).then(res => {
        if (res.code !== 200) {
          this.$message.error(res.message)
          return
        }
        return res.result
      })
    }
    ,
    handleDelaet() {
      this.form.resetFields()
    }
    ,
    handleCancel() {
      this.visible = false
    }
  },
  computed: {
    policysData() {
      return {
        title: '政策选择',
        width: `${70}%`,
        rowKey: 'promotionCode',
        way: 'post',
        tableUrl: window._CONFIG['domianDmsURL'] + '/promotion/findPromotionByProductCode',
        tableColums: [
          {
            title: '政策编号',
            align: 'center',
            dataIndex: 'promotionCode'
          },
          {
            title: '政策名称',
            align: 'center',
            dataIndex: 'promotionName'
          }
        ],
        multiple: false
      }
    },
    productConfig(){
      return {
        rowKey:'productCode'
      }
    }
  }
}
</script>

<style scoped>
.firstLine {
  padding: 0 3%;
}

.essential_text {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 8px;
}

.essential {
  padding: 0 0 10px 0;

}

.Poolbalance {
  border-bottom: 1px dashed #e8e8e8;
  padding-bottom: 15px;
}

.remain {
  padding-left: 10px;
  display: flex;
  flex-direction: row;
}

.remainF {
  width: 20%;
  margin-bottom: 18px;
  font-size: 14px;
}

.orderPay {
  display: flex;
  flex-direction: column;

}

.payText {
  color: red;
}

.payItems {
  font-size: 14px;
  margin: 4px 0;
}

/deep/ .ant-table-bordered .ant-table-tbody > tr > td {
  border-right: 1px dashed #e8e8e8 !important;
}
</style>